<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
Object obj=request.getSession().getAttribute("role_resource");
if(null==obj){
	response.setStatus(1000);
	return;
}
%> 
		<script type="text/javascript">
	
	//账单日
	var time_store =  new Ext.data.JsonStore( {
		fields : ["id", "text"],
		data:[	{id:"0",text:"05"},{id:"1",text:"07"},
				{id:"2",text:"15"},{id:"3",text:"17"},
				{id:"4",text:"20"},{id:"5",text:"25"},{id:"6",text:"30"}]
	});
	//状态
	var state_store = new Ext.data.JsonStore( {
		fields : ["id", "text"],
		data:[{id:"0",text:"停用"},{id:"1",text:"启用"},
			  {id:"2",text:"草稿"},{id:"3",text:"退回"}]
	});
	//卡类型下拉列表store
	var type_store= new Ext.data.JsonStore( {
		fields : ["id", "text"],
		data:[{id:"1",text:"纸质"},{id:"0",text:"电子"},{id:"2",text:"短信"}]
	}); 
	//p1显示列
	var p1_store = new Ext.data.JsonStore( {
		root : "data",
		idProperty:"",
		totalProperty: "total",
		fields : ["id","businpnt_no","foldout_name","foldout_prod_name","foldout_prod_weight",
				"foldout_pri","businpnt_name","period","period_begen","period_end","prod_no","prod_name"],
		url : "foldOut!listByCard.action"
	});
	//p2显示 列
	var p2_store = new Ext.data.JsonStore( {
		root : "data",
		fields : ["foldout_index","foldout_prod_name","price","foldout_prod_weight","foldout_pri"],
		url : "foldOut!listFoldoutDetails.action"
	});
	//生成插页id
	var feId_store = new Ext.data.JsonStore( {
		root : "data",
		fields : ["id"],
		url : "foldOut!feId.action"
	});
	//外包商下拉列表
	var bus_store=new Ext.data.JsonStore( {
		root : "data",
		fields : ["id","text"],
		url :"foldOut!listEpiboly.action"
	});
	//条件查询外包商下拉列表
	var bus_store1=new Ext.data.JsonStore( {
		root : "data",
		fields : ["id","text"],
		url :"foldOut!listEpiboly.action",
		listeners : {
			'load': function() {
				var RecordName = Ext.data.Record.create([
					{name: 'id'},
					{name: 'text'}
				]);
				var newRecord = new RecordName({
				    id:'',
					text: '全部'
				});
				this.insert(0,newRecord);
			}
		}
	});
	//搜索条件模板类型下拉列表
	var day_store= new Ext.data.JsonStore( {
		fields : ['id', 'text'],
		data:[{id:"",text:"全部"},{id:"01",text:"01"},{id:"02",text:"02"},{id:"03",text:"03"},{id:"04",text:"04"}
			,{id:"05",text:"05"},{id:"06",text:"06"},{id:"07",text:"07"},{id:"08",text:"08"},{id:"09",text:"09"}
			,{id:"10",text:"10"},{id:"11",text:"11"},{id:"12",text:"12"},{id:"13",text:"13"},{id:"14",text:"14"}
			,{id:"15",text:"15"},{id:"16",text:"16"},{id:"17",text:"17"},{id:"18",text:"18"},{id:"19",text:"19"}
			,{id:"20",text:"20"},{id:"22",text:"22"},{id:"23",text:"23"},{id:"24",text:"24"},{id:"25",text:"25"}
			,{id:"26",text:"26"},{id:"27",text:"27"},{id:"28",text:"28"},{id:"29",text:"29"},{id:"30",text:"30"}
			,{id:"31",text:"31"}]
	});
	bus_store.load();
	//bus_store1.load();
	bus_store1.load({callback:function(){
		Ext.getCmp("types").setValue("");
		Ext.getCmp("times").setValue("");
	}});
	
	//提交
	var opr_type;//传给ajax url属性的action字符串
	var page_param={};//传值参数对象
	
	function pageRequest(){
		var url="";
		if("add"==opr_type){
			url = "organization!add.action";
			page_param = {};
		}else if("edit"==opr_type){
			url="organization!update.action";
			page_param = {};
		}else if("del"==opr_type){
			url="organization!delete.action";
			page_param = {};
			var record =Ext.getCmp("org_grid").getSelectionModel().getSelected();
			page_param={
				id:record.data.id,
				supperId:record.data.supperId
			};
		}	
		//ajax提交
    	Ext.Ajax.request( {
    		url:url,
    		params:page_param,
    		success: function(response, opts){
				var d=eval("("+response.responseText+")");
				if(d.success){
					//Ext.Msg.alert("成功","操作成功");
					Ext.Msg.show({
		   				title:"提示",
		   				msg:"操作成功!",
		   				buttons:Ext.Msg.OK,
		   				icon: Ext.MessageBox.INFO
						});
					store.load({params:{parentId:page_param.supperId}});
					Ext.getCmp("foldout_tree").getNodeById(page_param.supperId).reload();
					Ext.getCmp("foldout_panel").layout.setActiveItem(0);
				} else {
					//Ext.Msg.alert("失败","操作失败");
					Ext.Msg.show({
		   				title:"提示",
		   				msg:"操作失败!",
		   				buttons:Ext.Msg.OK,
		   				icon: Ext.MessageBox.ERROR
						});
				}
			},
			failure: function(response, opts){
				
			}
    	});
	}
	
	
	var p1 = {
		id : "p1Grid",
		xtype : "grid",
		autoheight : true, 
		loadMask : true,//在加载数据时遮罩住元素,替换元素Updater的加载提示器，并且在初始化加载之后销毁
		autoExpandColumn:"businpnt_name",//自动填充
		autoExpandMin : 100,//自动填充最小宽度
		store :p1_store,
		headersDisabled: true,
		columns : [ new Ext.grid.RowNumberer( {header : "序号",width:35}), 
				{dataIndex : "id",header : "插页编号",hidden:true,menuDisabled: true}, 
				{dataIndex : "prod_name",header : "卡产品名称",menuDisabled: true}, 
	            {dataIndex : "businpnt_name",header : "外包商名称",id:"businpnt_name",menuDisabled: true},                  
	            {dataIndex : "period_begen",header : "开始月",menuDisabled: true},
	            {dataIndex : "period_end",header : "截止月",menuDisabled: true},
	            {dataIndex : "period",header : "账单日",menuDisabled: true}
		],
		//查询条件
		tbar:["&nbsp&nbsp外包商: ",
			{id:"types", xtype:"billCombox", store:bus_store1, width:120,
				listeners:{
		         "select": function(comb,rcord,index){
		         	var node = Ext.getCmp("foldout_tree").getSelectionModel().getSelectedNode();
		         	if(node&&node.isLeaf()){
		         			p1_store.baseParams["fp.businpnt_no"] = this.getValue();
		    	         	p1_store.load({params :{start:0,limit:limit}}); //根据选中节点动态刷新列表
			        	}
			        	else
			        	{
			        	 //Ext.Msg.alert("错误", "未选中任何卡产品,无法进行此操作!");
			        	 Ext.Msg.show({
							 title:"警告",
							 msg: "没有选中任何行信息，无法进行外包商条件查询操作!",
							 buttons: Ext.Msg.OK,
							 animEl: "elId",
							icon:Ext.MessageBox.WARNING
			});
			        	}
		         	}
		    	}
			},
			"&nbsp&nbsp账单日:",
			{id:"times", xtype:"billCombox", store:sys_store.seachStmtdate, width: 120,
				listeners:{
			    	"select": function(comb,rcord,index){
			         	var node = Ext.getCmp("foldout_tree").getSelectionModel().getSelectedNode();
			         	if(node&&node.isLeaf()){
		    	         	if(""==comb.getValue()){
		    	         		p1_store.baseParams["fp.period"] = null;
		    	         	}else{
		    	         		p1_store.baseParams["fp.period"] = comb.getRawValue();
		    	         	}
		         			
		    	         	p1_store.load({params :{start:0,limit:limit}}); //根据选中节点动态刷新列表
						} else {
			        		//Ext.Msg.alert("错误", "未选中任何卡产品,无法进行此操作!");
			        		Ext.Msg.show({
							 	title:"警告",
							 	msg: "没有选中任何行信息，无法进行账单日条件查询操作!",
							 	buttons: Ext.Msg.OK,
								animEl: "elId",
								icon:Ext.MessageBox.WARNING
								});
			        	}
			        }
			    }
			}
		],
		buttonAlign : "center",
		bbar : new Ext.ux.PagingToolbar( {
			id:"review",
			pageSize : limit,
			store : p1_store
		}),
		buttons : [{
					text : "查看详情",
					handler : function() {
						opr_type = "foldOut!updfocedate.action";
						var record = Ext.getCmp("p1Grid").getSelectionModel().getSelected();
						if (record) {
							Ext.getCmp("foldout_panel").layout.setActiveItem(1);
							Ext.getCmp("areaform").setParam(record.data);
						}else{
							//Ext.Msg.alert("错误","没有选中任何行信息，无法进行此操作!");
							Ext.Msg.show({
							 	title:"警告",
							 	msg: "未选中任何数据,无法进行此操作!",
							 	buttons: Ext.Msg.OK,
							 	animEl: "elId",
								icon:Ext.MessageBox.WARNING
								});
							}
					}
				}]
	};

	
	var p2 = {
		id:"areaform",
		columnWidth: 1,
		xtype :"form",
		title:"模板基本信息",
		labelWidth:75, 
		bodyStyle : "padding:5px 0 0",
		defaultType : "textfield",
		items : [
			{id:"prod_name",fieldLabel:"卡产品名称",anchor:"100%",disabled:true},
			{id:"businpnt_name",fieldLabel:"外包商名称",anchor:"100%",xtype:"billCombox",
				store:bus_store,disabled:true,
				listeners:{
					"select":function(){
						p2_store.load({params:{"fp.businpnt_no":this.getValue()}});
						Ext.getCmp("businpnt_no").setValue(this.getValue());	
					}	
				}
			},
			{id:"period",fieldLabel:"账单日",anchor:"100%",xtype:"datefield",format:"d",disabled:true},
			{id:"period_begen",fieldLabel : "开始月",vtype: 'daterange',
       		endDateField: 'period_end',anchor:"100%",xtype:"datefield",format:"Y-m",disabled:true},
			{id:"period_end",fieldLabel : "截止月",anchor:"100%",vtype: 'daterange',
       		startDateField: 'period_begen',xtype:"datefield",format:"Y-m",disabled:true},
       		{
			xtype:"grid",
			enableColumnMove:false,
			enableHdMenu:false,
			title:"插页纸槽个性化设置",
			loadMask : true,
			autoExpandColumn:"feprod_name",//自动填充
			autoExpandMin : 100,//自动填充最小宽度
			autoHeight:true,
			border:false,
			store :p2_store,
			headersDisabled: true,
			columns : [ new Ext.grid.RowNumberer( {header : "序号",width : 35}), 
	            {dataIndex : "foldout_index",header : "插页纸槽编号",id:"fe_index"},
	            {dataIndex : "foldout_prod_name",header : "插页纸广告名称",id:"feprod_name"},
				{dataIndex : "price",header : "插页纸广告费用",id:"price"},
	            {dataIndex : "foldout_prod_weight",header : "克重"},
	            {dataIndex : "foldout_pri",id:"fe_pri",header : "优先级"}
	           ]
		  }
		],
		buttonAlign : "center",
		buttons : [{
			text : "返回",
			handler : function(){
				Ext.getCmp("foldout_panel").layout.setActiveItem(0);
			}
		}],
		setParam : function(data) {
			Ext.getCmp("prod_name").setValue(data.prod_name);
			Ext.getCmp("businpnt_name").setValue(data.businpnt_name);
			Ext.getCmp("period").setValue(data.period);
			Ext.getCmp("period_begen").setValue(data.period_begen);
			Ext.getCmp("period_end").setValue(data.period_end);
			p2_store.load({params:{"fp.id":data.id,"fp.businpnt_no":data.businpnt_no}});
		}
	};
	
	var foldout_pel = new Ext.Panel( {
		id:"master_panel",
		border : false, 
		layout : "border",
		items:[{
			id:"foldout_tree",
			boxMinHeight : 300,//最小高度
			xtype : "billTreePanel",
			dataUrl : "tree!product.action",
			root : new Ext.tree.AsyncTreeNode( {
				id : "root",
				expanded : true // 自动展开节点
					}),
			listeners : {
				"click"	: function(node) {
				    if(node.isLeaf()){
						Ext.getCmp("times").setValue("");//清空查询项
						Ext.getCmp("types").setValue("");//清空查询项
				    	p1_store.baseParams = {};
			    		p1_store.baseParams["fp.prod_no"] = node.id;
			    		p1_store.load({params:{start : 0,limit : limit}});
						Ext.getCmp("foldout_panel").layout.setActiveItem(0);
				    }
				}
			}
		}, {
			id:"foldout_panel",
			region: "center",
			border : false,		
			layout: "card",
			activeItem: 0,
			items: [p1,p2]
		} ]	
	});	
	
	var CenterPanel=Ext.getCmp("CenterPanel");
	CenterPanel.removeAll();
	CenterPanel.add(foldout_pel);
	CenterPanel.doLayout();
</script>